<template>
  <div>
    <el-menu
        class="el-menu-demo"
        mode="horizontal"
        background-color="#545c64"
        text-color="#fff"
        active-text-color="#ffd04b">
      <el-menu-item disabled></el-menu-item>
    </el-menu>
    <br>
    <el-card class="box-card">
      <el-form>
        <el-form-item label="账号">
          <el-input v-model="form.name"></el-input>
        </el-form-item>
        <el-form-item label="密码">
          <el-input v-model="form.password"></el-input>
        </el-form-item>
        <el-form-item label="确认密码">
          <el-input v-model="form.password1"></el-input>
        </el-form-item>
        <el-form-item label="电话">
          <el-input v-model="form.tele"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary"  @click="handleRegister">注册</el-button>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>

<script>
export default {
  name: "Register",
  data() {
    return {
      form: {
        name: '',
        tele: '',
        password: '',
        password1: '',
      }
    }
  },
  methods: {
    handleRegister() {
      if(this.form.password!=this.form.password1)
        this.$message("两次密码必须相同")
      this.$http.post('/register', this.form).then(res => {
        console.log(res);
        // res.data 为flask return回来的值
        // console(res.data);
        if(res.data != 'post ok')
          this.$message(res.data)
      }).catch(err => {
        console.log(err);
      })
      this.$router.push('/login')
    }
  }
}
</script>

<style scoped>
.box-card {
  width: 480px;
  margin: 0 auto;
}
</style>